# Qdrant服务健康检查脚本
# 使用方法：.\check_qdrant.ps1

Write-Host "正在检查Qdrant服务状态..." -ForegroundColor Green

# 检查HTTP API
try {
    $response = Invoke-RestMethod -Uri "http://localhost:6333/" -Method GET -TimeoutSec 5
    Write-Host "✓ HTTP API (端口 6333) - 正常" -ForegroundColor Green
    Write-Host "  状态: $($response.status)"
    Write-Host "  版本: $($response.version)"
    Write-Host "  时间: $($response.time)"
} catch {
    Write-Host "✗ HTTP API (端口 6333) - 异常" -ForegroundColor Red
    Write-Host "  错误: $($_.Exception.Message)"
}

# 检查集合信息
try {
    $collections = Invoke-RestMethod -Uri "http://localhost:6333/collections" -Method GET -TimeoutSec 5
    Write-Host "✓ 集合查询 - 正常" -ForegroundColor Green
    Write-Host "  集合数量: $($collections.result.collections.Count)"
    
    # 检查file_chunks集合
    $fileChunks = $collections.result.collections | Where-Object { $_.name -eq "file_chunks" }
    if ($fileChunks) {
        Write-Host "  file_chunks集合: 存在" -ForegroundColor Green
        try {
            $collectionInfo = Invoke-RestMethod -Uri "http://localhost:6333/collections/file_chunks" -Method GET -TimeoutSec 5
            Write-Host "    向量数量: $($collectionInfo.result.vectors_count)"
            Write-Host "    点数量: $($collectionInfo.result.points_count)"
        } catch {
            Write-Host "    无法获取集合详细信息" -ForegroundColor Yellow
        }
    } else {
        Write-Host "  file_chunks集合: 不存在" -ForegroundColor Yellow
    }
} catch {
    Write-Host "✗ 集合查询 - 异常" -ForegroundColor Red
    Write-Host "  错误: $($_.Exception.Message)"
}

Write-Host ""
Write-Host "检查完成。" -ForegroundColor Green